<?php

namespace App\Admin\Controllers;

use App\Ymx;
use Encore\Admin\Controllers\AdminController;
use Encore\Admin\Form;
use Encore\Admin\Grid;
use Encore\Admin\Show;
use App\Log;
use Illuminate\Support\Facades\Route;

class YmxController extends AdminController
{
    /**
     * Title for current resource.
     *
     * @var string
     */
    protected $title = 'App\Ymx';

    /**
     * Make a grid builder.
     *
     * @return Grid
     */
    protected function grid()
    {
        $grid = new Grid(new Ymx());

        $grid->filter(function($filter){

            // 去掉默认的id过滤器
            $filter->disableIdFilter();

            // 在这里添加字段过滤器
            $filter->like('SellerName', '卖家简称');

        });

        $grid->actions(function ($actions) {

//关闭行操作 删除

            $actions->disableDelete();

        });

        $grid->column('id', __('ID'));
        $grid->column('SellerName', __('卖家简称'))->display(function($text) {
            return str_limit($text, 12, '...');
        });
        $grid->column('StoreName', __('店铺ID'));
        $grid->column('Station', __('站点'));
        $grid->column('StoreState', __('店铺状态'));
        $grid->column('RegisteredEnterpriseName', __('注册企业名称'))->display(function($text) {
            return str_limit($text, 12, '...');
        });
        $grid->column('MainPhoneNumber', __('手机主卡号'));
        $grid->column('MinorPhoneNumber', __('手机副卡号'));
        $grid->column('StoreCollectionMethod', __('店铺收款方式'));
        $grid->column('CreditCardNumber', __('信用卡号'));
        $grid->column('DueDate', __('到期日期'));
//        $grid->column('PrimaryAccount', __('主账号'));
//        $grid->column('PrimaryPassword', __('主账号密码'));
//        $grid->column('OperatingAccount', __('账号2（运营）'));
//        $grid->column('OperatingPassword', __('账号2密码'));
//        $grid->column('FinanceAccount', __('账号3（财务）'));
//        $grid->column('FinancePassword', __('账号3密码'));
//        $grid->column('InventoryAccount', __('账号4（FBA库存）'));
//        $grid->column('InventoryPassword', __('账号4密码'));
//        $grid->column('BackupAccount1', __('账号5（备用字段1）'));
//        $grid->column('BackupPassword1', __('账号5密码'));
//        $grid->column('BackupAccount2', __('账号6（备用字段2）'));
//        $grid->column('BackupPassword2', __('账号6密码'));
        $grid->column('StoreGroup', __('店铺分组'));
        $grid->column('StoreNotes', __('店铺备注'));
//        $grid->filter(function () {
//
//            // 范围过滤器，调用模型的`onlyTrashed`方法，查询出被软删除的数据。
//            $filter->scope('trashed', '回收站')->onlyTrashed();
//
//        });

        return $grid;
    }

    /**
     * Make a show builder.
     *
     * @param mixed $id
     * @return Show
     */
    protected function detail($id)
    {
        $show = new Show(Ymx::findOrFail($id));

//        $show->field('id', __('ID'));
        $show->field('SellerName', __('卖家简称'));
        $show->field('StoreName', __('店铺ID'));
        $show->field('Station', __('站点'));
        $show->field('StoreState', __('店铺状态'));
        $show->field('RegisteredEnterpriseName', __('注册企业名称'));
        $show->field('MainPhoneNumber', __('手机主卡号'));
        $show->field('MinorPhoneNumber', __('手机副卡号'));
        $show->field('StoreCollectionMethod', __('店铺收款方式'));
        $show->field('CreditCardNumber', __('信用卡号'));
        $show->field('DueDate', __('到期日期'));
        $show->field('PrimaryAccount', __('主账号'));
        $show->field('PrimaryPassword', __('主账号密码'));
        $show->field('OperatingAccount', __('账号2（运营）'));
        $show->field('OperatingPassword', __('账号2密码'));
        $show->field('FinanceAccount', __('账号3（财务）'));
        $show->field('FinancePassword', __('账号3密码'));
        $show->field('InventoryAccount', __('账号4（FBA库存）'));
        $show->field('InventoryPassword', __('账号4密码'));
        $show->field('BackupAccount1', __('账号5（备用字段1）'));
        $show->field('BackupPassword1', __('账号5密码'));
        $show->field('BackupAccount2', __('账号6（备用字段2）'));
        $show->field('BackupPassword2', __('账号6密码'));
        $show->field('StoreGroup', __('店铺分组'));
        $show->field('StoreNotes', __('店铺备注'));


//        $show->divider();
        return $show;
    }

    /**
     * Make a form builder.
     *
     * @return Form
     */
    protected function form()
    {
        $form = new Form(new Ymx());

//        Route::currentRouteName();

//        dd(Route::currentRouteName());
        $a =  substr(Route::currentRouteName(),strripos(Route::currentRouteName(),".")+1);
        

        $form->text('SellerName', __('卖家简称'));
        $form->text('StoreName', __('店铺ID'));
        $form->text('Station', __('站点'));
        $form->text('StoreState', __('店铺状态'));
        $form->text('RegisteredEnterpriseName', __('注册企业名称'));
        $form->mobile('MainPhoneNumber', __('手机主卡号'));
        $form->mobile('MinorPhoneNumber', __('手机副卡号'));
        $form->text('StoreCollectionMethod', __('店铺收款方式'));
        $form->text('CreditCardNumber', __('信用卡号'));
        $form->datetime('DueDate', __('到期日期'));
        $form->text('PrimaryAccount', __('主账号'));
        $form->password('PrimaryPassword', __('主账号密码'));
        $form->text('OperatingAccount', __('账号2（运营）'));
        $form->password('OperatingPassword', __('账号2密码'));
        $form->text('FinanceAccount', __('账号3（财务）'));
        $form->password('FinancePassword', __('账号3密码'));
        $form->text('InventoryAccount', __('账号4（FBA库存）'));
        $form->password('InventoryPassword', __('账号4密码'));
        $form->text('BackupAccount1', __('账号5（备用字段1）'));
        $form->password('BackupPassword1', __('账号5密码'));
        $form->text('BackupAccount2', __('账号6（备用字段2）'));
        $form->password('BackupPassword2', __('账号6密码'));
        $form->text('StoreGroup', __('店铺分组'));
        $form->text('StoreNotes', __('店铺备注'));


        return $form;
    }
}
